﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Login : System.Web.UI.Page
{

    private UserInfo user = new UserInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        this.txtUserNameLogin.Focus();
        if (!Page.IsPostBack)
        {
            if (Session["user"] != null)
            {
                this.Log_in1.Visible = false;
                this.Log_out1.Visible = true;

            }
            else
            {
                this.Log_in1.Visible = true;
                this.Log_out1.Visible = false;
            }
            if (Request.Params.Get("err") == "true")
            {
                this.lblError.Text = Constant.MESSAGE_ERROR_FAIL_LOGIN;
            }
        }
        else
        {
        }
    }
    protected void btnLoginMain_Click(object sender, EventArgs e)
    {
        user.StrUserName = this.txtUserNameLogin.Text;
        user.StrPassWord = this.txtPasswordLogin.Text;

        ProLogin plLogin = new ProLogin();
        user = plLogin.CheckLogin(user);

        if (user == null)
        {
            Response.Redirect("login.aspx?err=true");
        }
        else
        {
            //Session["user"] = this.txtUserName.Text;

            Session.Timeout = 500000;
            Session.Add("user", this.txtUserNameLogin.Text);
            Session.Add("userinfo", user);
            //HttpCookie cookie = new HttpCookie("LoginForm");
            //cookie.Values.Add("Username", "username");
            //cookie.Expires = DateTime.Now.AddDays(14);
            //HttpContext.Current.Response.Cookies.Add(cookie);
            Response.Redirect("default.aspx?uid=" + this.txtUserNameLogin.Text);
        }
    }

    protected void btnResetMain_Click(object sender, EventArgs e)
    {
        this.txtUserNameLogin.Text = "";
        this.txtPasswordLogin.Text = "";
    }
}


